package com.isoft.service.tableservice;

import com.isoft.dao.tabledao.DfmeStlsDao;
import com.isoft.entity.tableentity.dfme_stls.DfmeStlsMsg;
import com.isoft.entity.tableentity.dfme_stls.DfmeStlsStnd;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.List;

@Service
@Slf4j
public class DfmeStlsService {
    @Autowired
    DfmeStlsDao dfmeStlsDao;
    public int insertmsg(DfmeStlsMsg dfmeStlsMsg) throws Exception{
        Timestamp create_time = new Timestamp(System.currentTimeMillis());
         dfmeStlsDao.insertMeta(create_time,dfmeStlsMsg.getDfmeStlsMeta());
        dfmeStlsDao.insertDflt(dfmeStlsMsg.getDfmeStlsMeta().getSeqn(),create_time,dfmeStlsMsg.getDfmeStlsDflt());
        List<DfmeStlsStnd> stndList = dfmeStlsMsg.getDfmeStlsDflt().getStndList();
        if (stndList != null&&! stndList.isEmpty()){
            for (int i = 0; i < stndList.size(); i++) {
                DfmeStlsStnd dfmeStlsStnd = stndList.get(i);
                return dfmeStlsDao.insertStnd(dfmeStlsMsg.getDfmeStlsMeta().getSeqn(),create_time,dfmeStlsStnd);

            }
        }

        return 1;
    }
}
